
import { VxeGridPropTypes } from "vxe-table/types/grid";
import XEUtils from "xe-utils";

export const columns: VxeGridPropTypes.Columns = [
  {type: 'checkbox', width: 50, fixed: 'left',},
  {type: 'seq', title: '序号', treeNode: false, visible: false, width: 60,},
  {field: 'ID', title: 'ID', width: 60, visible: false,},
  {field: 'bill.ioTypeDict.label', title: '操作类型', sortable: false, width: 100, cellRender: {name: 'BillType'},},
  {field: 'bill.code', title: '关联单据', sortable: false, visible: true, width: 160, },
  {field: 'goods.cate.name', title: '类别', sortable: false, minWidth: 80,},
  {field: 'goods.name', title: '货物名称', sortable: false, minWidth: 130,},
  {field: 'goods.code', title: '货物编号', sortable: false, minWidth: 90},
  {field: 'goods.unit', title: '单位', sortable: false, visible: false, width: 'auto',},
  {field: 'goods.specs', title: '规格', sortable: false, visible: false, width: 'auto',},
  {field: 'goods.barcode', title: '条码', sortable: false, visible: false, width: 'auto',},
  {field: 'warehouse.name', title: '仓库', sortable: false, minWidth: 80,},
  {field: 'qty', title: '库存变化', sortable: false, width: 80,
  formatter({cellValue, row}) {
    return cellValue*row.mark
  },},
  {field: 'CreatedAt', title: '库存变动时间', visible: true, sortable: false, width: 170,
  formatter({cellValue}) {
      return XEUtils.toDateString(cellValue)
  },},
  {field: 'memo', title: '备注', visible: true, sortable: false, minWidth: 90,},
];

/**
 * 迭代 禁用不可用的分类
 * @param parent 商品分类列表
 * @returns 
 */
export function deep(parent:any[]) {
  parent.forEach(e => {
    e.disabled = e.enable !== 1
    e.checked = false
    if (e.attrs && e.attrs.length > 0) {
      e.attrs.forEach(a => a.checked = false)
    }
    if (e.children && e.children.length > 0) deep(e.children)
  })
  return parent
}

